package br.com.mmm.javacenter.framework.view.formatters;

import java.math.BigInteger;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;

import br.com.mmm.javacenter.framework.annotations.FormatterComponent;

@FormatterComponent({
	Number.class
})
public class NumberFormatter implements Formatter<Number>{
	private static NumberFormat nf = DecimalFormat.getInstance(new Locale("pt", "BR"));	
	static{
		nf.setMinimumIntegerDigits(1);
		nf.setMinimumFractionDigits(2);
	}
	public String format(Number object) {
		if(object.getClass() == long.class ||
		   object.getClass() == int.class ||
		   object.getClass() == byte.class ||
		   object.getClass() == short.class ||
		   object.getClass() == BigInteger.class ||
		   object.getClass() == Long.class ||
		   object.getClass() == Integer.class ||
		   object.getClass() == Byte.class ||
		   object.getClass() == Short.class){
			nf.setMinimumFractionDigits(0);
			nf.setMaximumFractionDigits(0);
		}else{
			nf.setMinimumFractionDigits(2);
			nf.setMaximumFractionDigits(2);
		}
		
		
		return nf.format(object);
	}

}
